import request from '@/utils/request'

/**
 * 获取商品分类
 * @param {number} param.currPage 当前页
 * @param {number} param.pageSize 页容
 */
export function GetShopClass(param) {
    return request({
        url: '/classify/query',
        method: 'Post',
        data: {
            currPage: param.currPage,
            pageSize: param.pageSize
        }
    })
}

/**
 * 添加商品分类
 * @param {number} name  分类名称
 * @param {string} sortNumber 排序
 */
export function AddShopClass(param) {
    return request({
        url: '/classify/add',
        method: 'Post',
        data: {
            name: param.name,
            sortNumber: param.sortNumber
        }
    })
}

/**
 * 修改商品分类
 * @param {number} name  分类名称
 * @param {string} sortNumber 排序
 * @param {number} id  商品分类id
 */
export function SetShopClass(param) {
    return request({
        url: '/classify/update',
        method: 'Post',
        data: {
            name: param.name,
            sortNumber: param.sortNumber,
            id: param.id
        }
    })
}

/**
 * 删除商品分类信息
 * @param {number} id 商品分类信息id
 */
export function DeleteShopClass(id) {
    return request({
        url: '/classify/delete',
        method: 'Post',
        data: {
            id
        }
    })
}

/**
 * 获取商品列表
 * @param {number} param.currPage 当前页
 * @param {number} param.pageSize 页容
 * @param {string} param.searchText 搜索
*/
export function GetShopList(param) {
    return request({
        method: 'Post',
        url: '/commodity/query',
        data: {
            currPage: param.currPage,
            pageSize: param.pageSize,
            searchText: param.searchText
        }
    })
}

/**
 * 添加商品
 * @param {Array} param.title           商品名称
 * @param {Array} param.carouselIdList  轮播图id数组
 * @param {Array} param.classifyIdList  分类id数组
 * @param {Number}param.commodityPrice  商品价格
 * @param {String}param.details         商品详情
 * @param {Array} param.detailIdList    商品详情图
 * @param {number}param.unit            单位：个/条/件
 */
export function AddShopInfo(param) {
    return request({
        method: 'Post',
        url: '/commodity/add',
        data: {
            title: param.title,
            carouselIdList: param.carouselIdList,
            classifyIdList: param.classifyIdList,
            commodityPrice: param.commodityPrice,
            details: param.details,
            detailIdList: param.detailIdList,
            unit: param.unit
        }
    })
}

/**
 * 修改商品信息
 * @param {*} id 商品id
 * @returns 
 */
export function SetShopInfo(param) {
    return request({
        method: 'Post',
        url: '/commodity/update',
        data: {
            id: param.id,
            title: param.title,
            carouselIdList: param.carouselIdList,
            classifyIdList: param.classifyIdList,
            commodityPrice: param.commodityPrice,
            details: param.details,
            detailIdList: param.detailIdList,
            unit: param.unit
        }
    })
}

/**
 * 添加商品规格
 * @param {number} param.commodityId  商品id
 * @param {number} param.pictureId    商品规格图片id
 * @param {number} param.price        商品规格价格
 * @param {string} param.specification 规格描述
 */
export function AddSpecification(param) {
    return request({
        url: '/commodity/specifications/add',
        method: 'Post',
        data: {
            commodityId: param.commodityId,
            pictureId: param.pictureId,
            price: param.price,
            specification: param.specification
        }
    })
}


/**
 * 删除商品
 * @param {number} id 商品id
 */
export function DeleteShop(id) {
    return request({
        url: '/commodity/delete',
        method: 'Post',
        data: {
            id
        }
    })
}